<?php 
header("Content-type:text/html;charset=utf-8");
//输入提示信息 3秒跳转
function redirect($url,$msg)
{
	echo $msg.'<a href="'.$url.'">如果没有跳转请点这里跳转</a>';
    header("refresh:3;url=$url");
}
function uploadfile($filename,$filepath='./images/',$allowtype=array(
    "jpg","jpeg","png","gif","Bmp","flv"
	)){
	if($_FILES["$filename"]["error"]>0){
		switch ($_FILES["$filename"]["error"]) {
			case 1:
			echo "文件尺寸超过了配置文件的最大值"; exit;
		    case 3:
		    echo "0部分文件上传"; exit;
		    case 4:
		    	echo "没有选择文件";
		    	break;
		    default:echo "未知错误"; exit;
		}
	}
	else
	{
		$suffix=strrchr($_FILES["filename"]["name"], '.');
		if(!in_array(ltrim($suffix,'.'), $allowtype)){
			echo "文件类型为".$suffix."!<br/>";
			echo "文件类型不正确！只能选择扩展名为jpg,jpeg,png,gif,Bmp,flv类型的文件！";
			exit;
		}
	$newname=date("YmdHis").rand(100,999).$suffix;
	if (!move_uploaded_file($_FILES["$filename"]["tmp_name"],$filepath.$newname)) {
	}
	else {		
		return $filepath.$newname;
	}

	}
}
?>
